// pages/user/index/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
      user:'',
      imgUrl: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getUser()
    this.setData({
      imgUrl: app.imgUrl
    })
      wx.stopPullDownRefresh()

  },
  getUser(){
      const token = wx.getStorageSync('token')
      wx.request({
        url: app.apiUrl+'/users',
        method:"GET",
        header:{
          "token":token
        },
        success: res=>{
          //   console.log(res)
          
          this.setData({
              user:res.data.data
          })
      }
  }
      )
  },
  logout(){
      const app = getApp()
      const token = wx.getStorageSync('token')
      const user = wx.getStorageSync("user");
    wx.request({
      url: app.apiUrl+'/user/logout/'+user.userId,
      method:"GET",
      header:{
          "token":token
      },
      success:res=>{
          console.log(res)
          wx.removeStorageSync('user')
          wx.removeStorageSync('token')
          this.setData({
              user:''
          })
      }
    })
  },
  onPullDownRefresh(){
      this.onLoad()
  },
  
})